<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <meta http-equiv="X-UA-Compatible" content="ie=edge">
  <title>Document</title>
</head>

<body>
  <script>
    // 获取上个页面传来的search 值
    // location.search//设置或返回URL的参数部分。 ?后的参数   "?id=888&age=28&name=zhang
    console.log(location.search)// ?id=876&age=28&name=zhang
    // id=888&age=28&name=zhang  参数序列化后的对象  {id:888,age:28,name:'zhang'}
    var searchStr = location.search.substr(1)//id=888&age=28&name=zhang
    console.log(searchStr)
    var id = searchStr.substr(searchStr.indexOf("id=") + 3, 3)
    console.log(id)


    // 获取地址栏参数的方法
    function getParams(key) { //id   888   age  28  name  zhang
      var searchStr = location.search.substr(1);//id=888&age=28&name=zhang
      var arr = searchStr.split("&");//["id=888","age=28","name=zhang"]
      for (var i = 0; i < arr.length; i++) {
        var parr = arr[i].split("="); //["id",888]   ["age",28]  ["name","zhang"]
        if (key == parr[0]) {
          return parr[1]
        }
      }
    }
    var age = getParams("age")
    console.log(age)
    var name = getParams("name");
    console.log(name)

  </script>
</body>

</html>